#!/usr/bin/env python

from __future__ import with_statement

def read_bugzilla(name):
    res = {}
    current = {}
    with open(name) as f:
        for line in f:
            line = line.strip()
            if line == '---------------------------------------':
                current = {}
            else:
                parsed = line.split(':')
                if len(parsed) > 1:
                    k = parsed[0]
                    v = parsed[1].strip()
                    if parsed[0] == 'bug_id':
                        res[v] = current
                    else:
                        current[k] = v
    return res

merged = read_bugzilla('bz-merged')
unmerged = read_bugzilla('bz-unmerged')

for b in merged:
    details = merged[b]
    status = details['bug_status']
    resolution = details['resolution']
    #print b, status, resolution
    if status != 'VERIFIED' or resolution != 'FIXED':
        print "{0} was merged but it's {1} {2}".format(b, status, resolution) 

for b in unmerged:
    details = unmerged[b]
    status = details['bug_status']
    resolution = details['resolution']
    #print b, status, resolution
    if status == 'VERIFIED' and resolution == 'FIXED':
        print "{0} was not merged but it's {1} {2}".format(b, status, resolution) 
